package com.changli02.method_lifecycle;

public class ThreadTest {
    public static void main(String[] args) {
        //Thread 构造器 name:线程名
        new Thread ("线程1"){
            @Override
            public void run() {
                for (int i = 1; i <=100 ; i++) {
                    if((i&1) ==1 ){
//                        try {
//                            Thread.sleep(1000);
//                        } catch (InterruptedException e) {
//                            throw new RuntimeException(e);
//                        }
                        System.out.println(Thread.currentThread().getName()+"   "
                                +Thread.currentThread().getPriority()+"->"+i);
//                        if(i% 20 == 0){
//                            Thread.yield();
//                        }
                    }

                }
            }
        }.start();
        Thread.currentThread().setName("主线程");
        Thread  maint =Thread.currentThread();
        maint.setPriority(Thread.MAX_PRIORITY);



//        Thread t1 = new Thread1("线程2");
//        t1.start();


        for (int i = 1; i <=100 ; i++) {
            if((i&1) !=1 ){
                System.out.println(Thread.currentThread().getName()+"   "
                        +Thread.currentThread().getPriority()+"->"+i);
//                if(i%20==0){
//                    try {
//                        t1.join();
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                }
            }

        }
//        System.out.println("t1是否存活？"+t1.isAlive());
    }


}




class Thread1 extends Thread {
    public Thread1(String name) {
        super(name);
    }
    @Override
    public void run() {
        for(int i=1 ;i<=100;i++){
            if((i&1)==1){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}